#define DEBUG
#include <cstdio>
#define MAXN 100000
#define MAXM 100000

using namespace std;

int getFa(int *f, int o) {
  if (f[o]!=o) {
    f[o]=getFa(f, f[o]);
  }
  return f[o];
}

void sort(long long a[][3], int l, int r) {
  int i=l, j=r, mid=a[(l+r)/2][0], temp;
  for (; i<=j; ) {
    for (; a[j][0]>mid; j--);
    for (; a[i][0]<mid; i++);
    if (i<=j) {
      for (int k=0; k<3; k++) {
	temp=a[i][k], a[i][k]=a[j][k], a[j][k]=temp;
      }
      i++, j--;
    }
  }
  if (i<r) {
    sort(a, i, r);
  }
  if (j>l) {
    sort(a, l, j);
  }
}

int main() {
#ifdef DEBUG
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
#endif

  static int a[MAXN+1], node[MAXN+1];
  static long long side[MAXM+1][3];
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i=1; i<=n; i++) {
    node[i]=i;
    scanf("%d", a+i);
  }
  for (int i=1; i<=m; i++) {
    scanf("%lld %lld %lld", side[i]+1, side[i]+2, side[i]);
    side[i][0]-=a[side[i][1]]+a[side[i][2]];
  }

  sort(side, 1, m);
  long long ans=0;
  for (int i=1; i<=m; i++) {
    if (getFa(node, side[i][1])!=getFa(node, side[i][2])) {
      ans+=side[i][0];
      node[getFa(node, side[i][1])]=getFa(node, side[i][2]);
    }
  }

  printf("%lld", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
